package cn.tedu.micro.demo.rabbitmq.controller;

import cn.tedu.micro.demo.rabbitmq.pojo.UserMsg;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.core.MessagePropertiesBuilder;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SendController {
    @Autowired
    RabbitTemplate rabbitTemplate;
    @GetMapping("/send")
    public String send(String  msg){
//        rabbitTemplate.convertAndSend("demo-ex","",msg);
        MessageProperties properties = MessagePropertiesBuilder.newInstance().build();
        properties.setAppId("66");
        Message message = new Message(msg.getBytes(),properties);
        rabbitTemplate.convertAndSend("demo-ex","",message);
        return "ok";
    }
    @GetMapping("/send/user")
    public String sendUser(UserMsg userMsg){
        rabbitTemplate.convertAndSend("demo-ex","",userMsg);
        return "ok";
    }
}
